import UserConfigTs from "../../Managers/UserConfigTs";

cc.Class({
    extends: cc.Component,

    properties: {
        musicButton:{
            default:null,
            type:cc.Node
        },

        vibrationButton:{
            default:null,
            type:cc.Node
        },

        soundManager:{
            default:null,
            type:require("SoundManager")
        }
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.initSetting()
    },

    start () {

    },

    // update (dt) {},

    initSetting:function () {
        let musicOn = cc.sys.localStorage.getItem('user_setting_music_on')
        if(!musicOn){
            musicOn = cc.gg.enumConfig.SETTING.ON
        }else {
            musicOn = parseInt(musicOn)
        }
        this.musicButton.getComponent("SwitchButton").initSwitchButton(musicOn)
        this.musicButton.getComponent("SwitchButton").setFrame1Cb(function () {
            //use this.soundManager
            cc.find("Canvas/SoundManager").emit("sound_on")
            // this._soundOn()
        }.bind(this))
        this.musicButton.getComponent("SwitchButton").setFrame2Cb(function () {
            cc.find("Canvas/SoundManager").emit("sound_off")
            // this._soundOff()
        }.bind(this))

        let vibrationOn = cc.sys.localStorage.getItem('user_setting_vibration_on')
        if(!vibrationOn){
            vibrationOn = cc.gg.enumConfig.SETTING.ON
        }else {
            vibrationOn = parseInt(vibrationOn)
        }
        this.vibrationButton.getComponent("SwitchButton").initSwitchButton(vibrationOn)
        this.vibrationButton.getComponent("SwitchButton").setFrame1Cb(function () {
            this._vibrationOn()
        }.bind(this))
        this.vibrationButton.getComponent("SwitchButton").setFrame2Cb(function () {
            this._vibrationOff()
        }.bind(this))
    },

    // _soundOn:function () {
    //     cc.gg.tdUtil.doSendTdEvent("click_menu_setting_soundon","LobbySetting")
    //     cc.sys.localStorage.setItem("user_setting_music_on",cc.gg.enumConfig.SETTING.ON)
    //     cc.warn("sound on option here")
    //     UserConfigTs.soundOn = true
    // },
    //
    // _soundOff:function () {
    //     cc.gg.tdUtil.doSendTdEvent("click_menu_setting_soundoff","LobbySetting")
    //     cc.sys.localStorage.setItem("user_setting_music_on",cc.gg.enumConfig.SETTING.OFF)
    //     cc.warn("sound off option here")
    //     UserConfigTs.soundOn = false
    // },

    _vibrationOn:function () {
        cc.gg.tdUtil.doSendTdEvent("click_menu_setting_vibrationon","LobbySetting")
        cc.sys.localStorage.setItem("user_setting_vibration_on",cc.gg.enumConfig.SETTING.ON)
        cc.warn("vibration on option here")
        UserConfigTs.vibrateOn = true
    },

    _vibrationOff:function () {
        cc.gg.tdUtil.doSendTdEvent("click_menu_setting_vibrationoff","LobbySetting")
        cc.sys.localStorage.setItem("user_setting_vibration_on",cc.gg.enumConfig.SETTING.OFF)
        cc.warn("vibration on option here")
        UserConfigTs.vibrateOn = false
    },
});
